﻿using System;
using System.Globalization;
using System.Resources;
using System.Reflection;

/// <summary>
/// Custom workflow resources.
/// </summary>
internal static class ExtendedWorkflowResources
{
    // Fields
    public const string ApplyTransformToConfigurationFilesDisplayName = "ApplyTransformToConfigurationFilesDisplayName";
    public const string ConfigurationFilesHostDisplayName = "ConfigurationFilesHostDisplayName";
    public const string ConfigurationFilesPathDisplayName = "ConfigurationFilesPathDisplayName";
    public const string TransformConfigurationSystemTypeDisplayName = "TransformConfigurationSystemTypeDisplayName";
    public const string ApplyTransformToConfigurationFilesDescription = "ApplyTransformToConfigurationFilesDescription";
    public const string ConfigurationFilesHostDescription = "ConfigurationFilesHostDescription";
    public const string ConfigurationFilesPathDescription = "ConfigurationFilesPathDescription";
    public const string TransformConfigurationSystemTypeDescription = "TransformConfigurationSystemTypeDescription";
    public const string SourceFileNameDisplayName = "SourceFileNameDisplayName";
    public const string SourceFileNameDescription = "SourceFileNameDescription";
    public const string TransformFilePathDisplayName = "TransformFilePathDisplayName";
    public const string TransformFilePathDescription = "TransformFilePathDescription";
    public const string TransformScriptPathDisplayName = "TransformScriptPathDisplayName";
    public const string TransformScriptPathDescription = "TransformScriptPathDescription";
    public const string TargetTransformsDisplayName = "TargetTransformsDisplayName";
    public const string TargetTransformsDescription = "TargetTransformsDescription";
    public const string LocalPathToWebConfigUnderSourceRootDisplayName = "LocalPathToWebConfigUnderSourceRootDisplayName";
    public const string LocalPathToWebConfigUnderSourceRootDescription = "LocalPathToWebConfigUnderSourceRootDescription";
    public const string LocalFileNameToReplaceWithTransformFileDisplayName = "LocalFileNameToReplaceWithTransformFileDisplayName";
    public const string LocalFileNameToReplaceWithTransformFileDescription = "LocalFileNameToReplaceWithTransformFileDescription";
    public const string OverrideSourceWebConfigWithTransformFilePrePackagingDisplayName = "OverrideSourceWebConfigWithTransformFilePrePackagingDisplayName";
    public const string OverrideSourceWebConfigWithTransformFilePrePackagingDescription = "OverrideSourceWebConfigWithTransformFilePrePackagingDescription";
    public const string OverrideTransformsDisplayName = "OverrideTransformsDisplayName";
    public const string OverrideTransformsDescription = "OverrideTransformsDescription";
    public const string TransformFilePathForPrePackingingOverrideDisplayName = "TransformFilePathForPrePackingingOverrideDisplayName";
    public const string TransformFilePathForPrePackingingOverrideDescription = "TransformFilePathForPrePackingingOverrideDescription";
    public const string HideArgumentsDescription = "HideArgumentsDescription";
    public const string ActivityCategoryMiscellaneous = "Miscellaneous";
    public const string BuildControllerDescription = "BuildControllerDescription";
    public const string BuildDefinitionDescription = "BuildDefinitionDescription";
    public const string ProjectNameDescription = "ProjectNameDescription";
    public const string RequestedForDescription = "RequestedForDescription";
    public const string RunWorkFlowActivityDescription = "RunWorkFlowActivityDescription";
    public const string IncompleteRunWorkflowActivity = "IncompleteRunWorkflowActivity";
    public const string PriorityDescription = "PriorityDescription";
    public const string CustomGetVersionDescription = "CustomGetVersionDescription";
    public const string GetLastKnownGoodBuildActivityDescription = "GetLastKnownGoodBuildActivityDescription";
    public const string AvailableBuildsPatternDescription = "AvailableBuildsPatternDescription";
    public const string BuildLabelSourceControlScopeDescription = "BuildLabelSourceControlScopeDescription";
    public const string BuildLabelOwnerNameDescription = "BuildLabelOwnerNameDescription";
    public const string ExcludeLabelsForFailedBuildsDescription = "ExcludeLabelsForFailedBuildsDescription";
    public const string AcceptableBuildQualitiesDescription = "AcceptableBuildQualitiesDescription";
    public const string TeamProjectNameDescription = "TeamProjectNameDescription";
    public const string GetModifiedAssembliesActivityDescription = "GetModifiedAssembliesActivityDescription";
    public const string BaselineAssembliesFolderDescription = "BaselineAssembliesFolderDescription";
    public const string BuiltAssembliesDescription = "BuiltAssembliesDescription";
    public const string SkipRemoveTempFolderDescription = "SkipRemoveTempFolderDescription";
    public const string ShowVerboseLogOutputDescription = "ShowVerboseLogOutputDescription";
    public const string ToolPathDescription = "ToolPathDescription";
    public const string IgnoreAssemblyVersionChangeDescription = "IgnoreAssemblyVersionChangeDescription";
    public const string IgnoreAssemblyFileVersionChangeDescription = "IgnoreAssemblyFileVersionChangeDescription";
    public const string MappingTypeDisplayName = "MappingTypeDisplayName";
    public const string MappingTypeDescription = "MappingTypeDescription";
    public const string LocalItemDisplayName = "LocalItemDisplayName";
    public const string LocalItemDescription = "LocalItemDescription";
    public const string ServerItemDisplayName = "ServerItemDisplayName";
    public const string ServerItemDescription = "ServerItemDescription";
    public const string BaselineVersionDisplayName = "BaselineVersionDisplayName";
    public const string BaselineVersionDescription = "BaselineVersionDescription";
    public const string CustomWorkspaceMappingsDescription = "CustomWorkspaceMappingsDescription";
    public const string SourcesDirectoryDescription = "SourcesDirectoryDescription";
    public const string BinariesDirectoryDescription = "BinariesDirectoryDescription";
    private static ResourceManager s_resMgr = new ResourceManager("ExtendedWorkflowResources", Assembly.GetAssembly(typeof(ExtendedWorkflowResources)));

    // Methods
    public static string Format(string resourceName, params object[] args)
    {
        string format = Get(resourceName);
        if (args == null)
        {
            return format;
        }
        for (int i = 0; i < args.Length; i++)
        {
            if (args[i] is DateTime)
            {
                DateTime time = (DateTime)args[i];
                Calendar calendar = DateTimeFormatInfo.CurrentInfo.Calendar;
                if (time > calendar.MaxSupportedDateTime)
                {
                    args[i] = calendar.MaxSupportedDateTime;
                }
                else if (time < calendar.MinSupportedDateTime)
                {
                    args[i] = calendar.MinSupportedDateTime;
                }
            }
        }
        return string.Format(CultureInfo.CurrentCulture, format, args);
    }

    public static string Get(string resourceName)
    {
        return s_resMgr.GetString(resourceName, CultureInfo.CurrentUICulture);
    }

    public static bool GetBool(string resourceName)
    {
        return (bool)s_resMgr.GetObject(resourceName, CultureInfo.CurrentUICulture);
    }

    public static int GetInt(string resourceName)
    {
        return (int)s_resMgr.GetObject(resourceName, CultureInfo.CurrentUICulture);
    }

    // Properties
    public static ResourceManager Manager
    {
        get
        {
            return s_resMgr;
        }
    }
}
